package com.xrui.hbase.filter;


import com.xrui.hbase.ColumnName;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter;

import java.io.IOException;

/**
 * A column filter that limits the number of versions to 1.
 * <p>
 * <p> This filter restricts the number of cells returned for the column it applies to to 1. </p>
 * <p> Wraps the HBase {@link FirstKeyOnlyFilter}. </p>
 *
 * @deprecated Instead of using this filter, set the column's max values to 1.
 */

@Deprecated
public final class FirstKeyOnlyColumnFilter extends ColumnFilter {

    private static final long serialVersionUID = 1L;

    /**
     * {@inheritDoc}
     */
    @Override
    public Filter toHBaseFilter(ColumnName columnName/*, Context context*/) throws IOException {
        return new FirstKeyOnlyFilter();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object other) {
        // No state, so all FirstKeyOnlyFilters are the same
        return other instanceof FirstKeyOnlyColumnFilter;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        // No state, so all FirstKeyOnlyFilters are the same
        return new HashCodeBuilder().toHashCode();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return new ToStringBuilder(FirstKeyOnlyFilter.class).toString();
    }
}
